using DesignerProject;
using UnityEditor;
using UnityEngine;

[CanEditMultipleObjects]
[CustomEditor(typeof(SkillEditor))]
public class SkillEditor_Editor : Editor
{
    #region Field
    private SkillEditor tar;
    public SerializedProperty currMode;

    private SerializedProperty campType;
    private SerializedProperty skillArmsId;
    private SerializedProperty animType;
    private SerializedProperty beSkillArmsId;

    private SerializedProperty hitEffectId;
    private SerializedProperty hitEffectScale;
    private SerializedProperty isSkillBindBullet;

    private SerializedProperty bulletSpeed;
    private SerializedProperty bulletOffset;
    private SerializedProperty isCollimation;
    private SerializedProperty bulletEffectId;
    private SerializedProperty bulletEffectScale;

    private SerializedProperty buffEffectId;
    private SerializedProperty buffEffectScale;

    private GUILayoutOption opt = GUILayout.Width(130f);
    #endregion

    private void OnEnable()
    {
        tar = target as SkillEditor;
        currMode = GetProperty("currMode");

        campType = GetProperty("campType");
        skillArmsId = GetProperty("skillArmsId");
        animType = GetProperty("animType");
        beSkillArmsId = GetProperty("beSkillArmsId");

        hitEffectId = GetProperty("hitEffectId");
        hitEffectScale = GetProperty("hitEffectScale");
        isSkillBindBullet = GetProperty("isSkillBindBullet");

        bulletSpeed = GetProperty("bulletSpeed");
        bulletOffset = GetProperty("bulletOffset");
        isCollimation = GetProperty("isCollimation");
        bulletEffectId = GetProperty("bulletEffectId");
        bulletEffectScale = GetProperty("bulletEffectScale");

        buffEffectId = GetProperty("buffEffectId");
        buffEffectScale = GetProperty("buffEffectScale");
    }

    public override void OnInspectorGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.BeginVertical();

        EditorGUILayout.PropertyField(currMode, GetContent("选择模式"));
        EditorGUILayout.Space();
        if (tar.currMode == SkillEditor.Mode.ProcedureEdit)
        {
            DrawEditView();
        }
        else
        {
            DrawCheckView();
        }
        EditorGUILayout.Space();
        if (GUILayout.Button("创建兵种", GUILayout.Height(22f)))
        {
            tar.CreateActor();
        }
        if (GUILayout.Button("播放技能特效", GUILayout.Height(22f)))
        {
            tar.PlaySkillEffect();
        }
        if (GUILayout.Button("播放弹道特效", GUILayout.Height(22f)))
        {
            tar.PlayBulletEffect();
        }
        if (GUILayout.Button("播放Buff特效", GUILayout.Height(22f)))
        {
            tar.PlayBuffEffect();
        }
        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();
        serializedObject.ApplyModifiedProperties();
    }

    private void DrawCheckView()
    {
        if (DrawInspectorTool.DrawHeader("[兵种信息]"))
        {
            DrawInspectorTool.BeginContents();
            {
                DrawInspectorTool.GetLabelWidth(55f);
                EditorGUILayout.PropertyField(campType, GetContent("攻守阵营"), opt);
                EditorGUILayout.PropertyField(skillArmsId, GetContent("主动方"), opt);
                EditorGUILayout.PropertyField(beSkillArmsId, GetContent("被动方"), opt);
            }
            DrawInspectorTool.EndContents();
        }
    }
    private void DrawEditView()
    {
        if (DrawInspectorTool.DrawHeader("[兵种信息]"))
        {
            DrawInspectorTool.BeginContents();
            {
                DrawInspectorTool.GetLabelWidth(55f);
                EditorGUILayout.PropertyField(campType, GetContent("攻守阵营"), opt);
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(55f);
                    EditorGUILayout.PropertyField(skillArmsId, GetContent("主动方"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(animType, GetContent("动作"), opt);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(55f);
                    EditorGUILayout.PropertyField(beSkillArmsId, GetContent("被动方"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                }
                EditorGUILayout.EndHorizontal();
            }
            DrawInspectorTool.EndContents();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (DrawInspectorTool.DrawHeader("[技能特效]"))
        {
            DrawInspectorTool.BeginContents();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(hitEffectId, GetContent("受击"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(hitEffectScale, GetContent("缩放"), opt);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(70f);
                    EditorGUILayout.PropertyField(isSkillBindBullet, GetContent("绑定弹道测试"), opt);
                }
                EditorGUILayout.EndHorizontal();
            }
            DrawInspectorTool.EndContents();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (DrawInspectorTool.DrawHeader("[弹道特效]"))
        {
            DrawInspectorTool.BeginContents();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(bulletSpeed, GetContent("速度"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(bulletOffset, GetContent("弧度"), opt);
                    DrawInspectorTool.GetLabelWidth(55f);
                    EditorGUILayout.PropertyField(isCollimation, GetContent("是否瞄准"), opt);
                }
                EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(bulletEffectId, GetContent("特效"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(bulletEffectScale, GetContent("缩放"), opt);
                }
                EditorGUILayout.EndHorizontal();
            }
            DrawInspectorTool.EndContents();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (DrawInspectorTool.DrawHeader("[Buff特效]"))
        {
            DrawInspectorTool.BeginContents();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(buffEffectId, GetContent("特效"), opt);
                    DrawInspectorTool.GetLabelWidth(35f);
                    EditorGUILayout.PropertyField(buffEffectScale, GetContent("缩放"), opt);
                }
                EditorGUILayout.EndHorizontal();
            }
            DrawInspectorTool.EndContents();
        }
    }

    private SerializedProperty GetProperty(string pName)
    {
        return serializedObject.FindProperty(pName);
    }
    private GUIContent GetContent(string cStr)
    {
        return new GUIContent(cStr);
    }
}